<?php

class Coment extends CActiveRecord {
    /**
     * The followings are the available columns in table 'z_coment':
     * @var integer $id_coment
     * @var string $id_name
     * @var integer $id_post
     * @var string $autor
     * @var string $text
     * @var string $c_date
     * @var string $u_date
     */
    public $verifyCode;
    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }
    
    public function behaviors() {
        return array(
                'AutoTimestampBehavior' => array(
                        'class' => 'application.components.AutoTimestampBehavior',
                // вы можете указать дополнительные опции здесь
                )
        );
    }
    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'z_coment';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
                array('id_name, id_post, text', 'required'),
                array('id_post', 'numerical', 'integerOnly'=>true),
                array('c_date, u_date', 'safe'),
                            array('verifyCode', 'captcha', 'allowEmpty' => !extension_loaded('gd'), 'captchaAction' => 'site/captcha'
                        ,'on'=>'captch'),
                // The following rule is used by search().
                // Please remove those attributes that should not be searched.
                array('id_coment, id_name, id_post, autor, text, c_date, u_date', 'safe', 'on'=>'search'),
        );
    }
    public function safeAttributes() {

        return array('captch' => 'text, verifyCode',);
    }
    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
                'id_coment' => 'id',
                'id_name' => 'Категория',
                'id_post' => 'Сообщение',
                'autor' => 'Автор',
                'text' => 'Текст коментария',
                'c_date' => 'Дата создания',
                'u_date' => 'Дата изменения',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id_coment',$this->id_coment);

        $criteria->compare('id_name',$this->id_name,true);

        $criteria->compare('id_post',$this->id_post);

        $criteria->compare('autor',$this->autor,true);

        $criteria->compare('text',$this->text,true);

        $criteria->compare('c_date',$this->c_date,true);

        $criteria->compare('u_date',$this->u_date,true);

        return new CActiveDataProvider('Coment', array(
                        'criteria'=>$criteria,
        ));
    }
}